package com.springcloudalibaba.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: TongRui乀
 * @Date: 2019-11-25 9:45
 * @description：
 */
@RequestMapping("config")
@RestController
@RefreshScope
public class WebController {


    @Value("${user.name}")
    private String name;

    @Value("${user.age}")
    private String age;

    @Autowired
    private Environment environment;

    @GetMapping("getValue")
    public String getValue(){
        return this.name + "::" + this.age;
    }


    @GetMapping("getByKey/{key}")
    public String getByKey(@PathVariable String key){
        return this.environment.getProperty(key);
    }

}
